


//cd "C:\Users\creto\Desktop\chinese_students_2017\Submissions\ReStat\Replication Files 2022"
global path = "C:\Users\creto\Desktop\chinese_students_2017\"

*global path "C:\Users\Kevin Shih\Dropbox\Work\Research Projects\Active\chinese_students_2017"

clear
set more off

cap log close


*load data
	use "$path/Submissions/ReStat/Replication Files 2022/kswxy_data.dta", clear
	
	gen sample = 1 if balanced==1 & popwt03!=. 
	egen minsample = min(sample), by(citycode)
	drop sample
	rename minsample sample

	drop if citycode==.
	
	gen exports = dvalue/10000
	
	gen gdppc_true = gdppc*10
	
	gen stud_ot = stud_1 + stud_2 + stud_7 + stud_8
	gen stud_nonfunded = stud_tot - stud_univ_funded
	gen gdp_true = gdp*10000
	gen ln_gdp_true=ln(gdp_true)
	
	foreach x in as ba ma dr ot stem ss arts bus hi_admrate_p0_25 hi_admrate_p25_50 hi_admrate_p50_75 hi_admrate_p75_100 univ_funded nonfunded {
	gen sh_`x' = stud_`x'/stud_tot
	}
	


*set controls
global controls "chinatariff00_expw97 share_revenue_exw97 inputtariff02_expw97 contract_cons_exw97" 
label var contract_cons_exw97 "Contract Intensity"
label var share_revenue_exw97 "Export License"
label var chinatariff00_expw97 "Import Tariffs"
label var inputtariff02_expw97 "Input Tariffs"
label var ln_chinatariff_expw97 "Annual Import Tariffs"
label var ln_inputtariff_expw97 "Annual Input Tariffs"
	

*calculation for interquartile effect	
	sum iv_ntr if year==2013 & balanced==1, de
	local iqr_ivntr = r(p75) - r(p25)
	eststo clear







	**TABLE D.1:  COMPOSITION ANALYSIS
		
		
		
		rename stud_hi_admrate_p0_25 stud_ar_p025
		rename stud_hi_admrate_p25_50 stud_ar_p2550 
		rename stud_hi_admrate_p50_75 stud_ar_p5075
		rename stud_hi_admrate_p75_100 stud_ar_p75100
		rename stud_hi_instrspend_p0_25 stud_ie_p025 
		rename stud_hi_instrspend_p25_50 stud_ie_p2550 
		rename stud_hi_instrspend_p50_75 stud_ie_p5075
		rename stud_hi_instrspend_p75_100 stud_ie_p75100
		
		rename stud_funds_p_p0_25 stud_fp_p025
		rename stud_funds_p_p25_50 stud_fp_p2550 
		rename stud_funds_p_p50_75 stud_fp_p5075 
		rename stud_funds_p_p75_100 stud_fp_p75100
		rename stud_funds_po_p0_25 stud_fpo_p025
		rename stud_funds_po_p25_50 stud_fpo_p2550
		rename stud_funds_po_p50_75 stud_fpo_p5075
		rename stud_funds_po_p75_100 stud_fpo_p75100

*construct vars to make the factor to calculate elasticities
	gen stud_ug = stud_ba+stud_ma
	foreach var in 		   tot ug ma dr ot as ba				/// Level of study
					       stem ss bus arts 					/// field of study
						   ar_p025 ar_p2550 ar_p5075 ar_p75100 	/// admission rate
						   nonfunded univ_funded 				/// funded vs non funded students
						   fpo_p025 fpo_p2550 fpo_p5075 fpo_p75100 ///level of funding 
						   hhc_p025 hhc_p2550 hhc_p5075 hhc_p75100 ///human capital level, inequality
						   {
						   					   
							sort citycode year			 
						
							bys citycode: gen sh_stud_`var'02 = stud_`var'[_n-11]/pop[_n-11] if year==2013
		}
		

		
		sort citycode year
		foreach x in ar_p025 ar_p2550 ar_p5075 ar_p75100 ie_p025 ie_p2550 ie_p5075 ie_p75100 bus stem ss arts  univ_funded ///
				     fp_p025 fp_p2550 fp_p5075 fp_p75100 fpo_p025 fpo_p2550 fpo_p5075 fpo_p75100 hhc_p50100 hhc_p050 hhc_p75100 hhc_p025 hhc_p2550 hhc_p5075 {
			
			bys citycode: gen shc_stud_`x'_0213 = (stud_`x' - stud_`x'[_n-11]) / (pop[_n-11]) if year==2013
			bys citycode: gen ch_stud_`x'_tot_0213 = (stud_`x' - stud_`x'[_n-11]) / (stud_tot - stud_tot[_n-11]) if year==2013
			bys citycode: gen chsh_stud_`x'_tot_0213 = (stud_`x'/stud_tot) - (stud_`x'[_n-11]/stud_tot[_n-11]) if year==2013
		}
	
				gen shc_stud_nonfunded_0213 = shc_stud_tot_0213 - shc_stud_univ_funded_0213  if year==2013 & balanced==1

				
		foreach x in bus stem ss arts univ_funded {
		
			foreach l in as ba ma dr ot {
			
			bys citycode: gen shc_stud_`x'_`l'_0213 = (stud_`x'_`l' - stud_`x'_`l'[_n-11]) / (pop[_n-11]) if year==2013
			bys citycode: gen ch_stud_`x'_`l'_0213 = (stud_`x'_`l' - stud_`x'_`l'[_n-11]) / (stud_`l' - stud_`l'[_n-11]) if year==2013
			bys citycode: gen chsh_stud_`x'_`l'_0213 = (stud_`x'_`l'/stud_`l') - (stud_`x'_`l'[_n-11]/stud_`l'[_n-11]) if year==2013
		}
		}
		
			gen shc_stud_ug_0213 = shc_stud_as_0213  + shc_stud_ba_0213 
			gen shc_stud_ot_0213 = shc_stud_tot_0213 - shc_stud_ug_0213 - shc_stud_ma_0213 - shc_stud_dr_0213
		
	
	
			**BY LEVEL OF STUDY	
		
			    foreach l in as ba ma dr ot tot {
				sum stud_`l' if year==2002 & balanced==1
				local `l' = r(mean)
				}
				
			
		eststo TOT: reg shc_stud_tot_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode) 
				local beta_main = _b[iv_ntr]
				
				sum sh_stud_tot02
				estadd local elast = round((_b[iv_ntr]*(1/`r(mean)')*(1/10)),.01)
				
								
				/*
				eststo B: reg shc_stud_ug_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode) 
				estadd local prop= round((`ba'+`as')/(`tot'),.01)
				estadd local propeff = round(_b[iv_ntr]/`beta_main',.01)
				estadd local dprop = round(_b[iv_ntr]/`beta_main',.01) - round((`ba'+`as')/(`tot'),.01)
					
					local propB = round((`ba'+`as')/(`tot'),.01)
					local propeffB = round(_b[iv_ntr]/`beta_main',.01)
				
				sum sh_stud_ug02
				estadd local elast = round((_b[iv_ntr]*(1/`r(mean)')*(1/10)),.01)
				*/
				
				//Panel A
	
				eststo B1: reg shc_stud_as_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode) 
				estadd local prop= round((`as')/(`tot'),.01)
				estadd local propeff = round(_b[iv_ntr]/`beta_main',.01)
				estadd local dprop = round(_b[iv_ntr]/`beta_main',.01) - round((`as')/(`tot'),.01)
					
					local propB1 = round((`as')/(`tot'),.01)
					local propeffB1 = round(_b[iv_ntr]/`beta_main',.01)	
				
				sum sh_stud_as02
				estadd local elast = round((_b[iv_ntr]*(1/`r(mean)')*(1/10)),.01)
				
				eststo B2: reg shc_stud_ba_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode) 
				estadd local prop= round((`ba')/(`tot'),.01)
				estadd local propeff = round(_b[iv_ntr]/`beta_main',.01)
				estadd local dprop = round(_b[iv_ntr]/`beta_main',.01) - round((`ba')/(`tot'),.01)
					
					local propB2 = round((`ba')/(`tot'),.01)
					local propeffB2 = round(_b[iv_ntr]/`beta_main',.01)	
					
				sum sh_stud_ba02
				estadd local elast = round((_b[iv_ntr]*(1/`r(mean)')*(1/10)),.01)
				
				eststo C: reg shc_stud_ma_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode) 
				estadd local prop= round(`ma'/(`tot'),.01)
				estadd local propeff = round(_b[iv_ntr]/`beta_main',.01)
				estadd local dprop = round(_b[iv_ntr]/`beta_main',.01) - round((`ma')/(`tot'),.01)
				
					local propC = round(`ma'/(`tot'),.01)
					local propeffC = round(_b[iv_ntr]/`beta_main',.01)
					
				sum sh_stud_ma02
				estadd local elast = round((_b[iv_ntr]*(1/`r(mean)')*(1/10)),.01)	
					
				eststo D: reg shc_stud_dr_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode) 
				estadd local prop= round(`dr'/(`tot'),.01)
				estadd local propeff = round(_b[iv_ntr]/`beta_main',.01)
				estadd local dprop = round(_b[iv_ntr]/`beta_main',.01) - round((`dr')/(`tot'),.01)
				
					local propD = round(`dr'/(`tot'),.01)
					local propeffD = round(_b[iv_ntr]/`beta_main',.01)
				
				sum sh_stud_dr02
				estadd local elast = round((_b[iv_ntr]*(1/`r(mean)')*(1/10)),.01)
				
				eststo E: reg shc_stud_ot_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode) 
				estadd local prop= round(`ot'/(`tot'),.01)
				estadd local propeff = round(_b[iv_ntr]/`beta_main',.01)
				estadd local dprop = round(_b[iv_ntr]/`beta_main',.01) - round((`ot')/(`tot'),.01)
				
					local propE = round(`ot'/(`tot'),.01)
					local propeffE = round(_b[iv_ntr]/`beta_main',.01)
				
				sum sh_stud_ot02
				estadd local elast = round((_b[iv_ntr]*(1/`r(mean)')*(1/10)),.01)
	
		
		**BY FIELD OF STUDY
		
		foreach l in stem ss bus arts tot {
		sum stud_`l' if year==2002 & balanced==1
		local `l' = r(mean)
		}
		
			//Panel B
		
		
		eststo Z: reg shc_stud_tot_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode) 
		local beta_main = _b[iv_ntr]
		
		eststo A: reg shc_stud_stem_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode) 
		estadd local prop= round(`stem'/(`tot'),.01)
		estadd local propeff = round(_b[iv_ntr]/`beta_main',.01)
		estadd local dprop = round(_b[iv_ntr]/`beta_main',.01) - round((`stem')/(`tot'),.01)
		
			local propA = round(`stem'/(`tot'),.01)
			local propeffA = round(_b[iv_ntr]/`beta_main',.01)
		
		sum sh_stud_stem02
		estadd local elast = round((_b[iv_ntr]*(1/`r(mean)')*(1/10)),.01)	

		eststo B: reg shc_stud_ss_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode) 
		estadd local prop= round(`ss'/(`tot'),.01)
		estadd local propeff = round(_b[iv_ntr]/`beta_main',.01)
		estadd local dprop = round(_b[iv_ntr]/`beta_main',.01) - round((`ss')/(`tot'),.01)
		
			local propB= round(`ss'/(`tot'),.01)
			local propeffB = round(_b[iv_ntr]/`beta_main',.01)
			
		sum sh_stud_ss02
		estadd local elast = round((_b[iv_ntr]*(1/`r(mean)')*(1/10)),.01)		
		
		eststo C: reg shc_stud_bus_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode) 
		estadd local prop= round(`bus'/(`tot'),.01)
		estadd local propeff = round(_b[iv_ntr]/`beta_main',.01)
		estadd local dprop = round(_b[iv_ntr]/`beta_main',.01) - round((`bus')/(`tot'),.01)
		
			local propC= round(`bus'/(`tot'),.01)
			local propeffC = round(_b[iv_ntr]/`beta_main',.01)	
		
		sum sh_stud_bus02
		estadd local elast = round((_b[iv_ntr]*(1/`r(mean)')*(1/10)),.01)	
	
		eststo D: reg shc_stud_arts_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode) 
		estadd local prop= round(`arts'/(`tot'),.01)
		estadd local propeff = round(_b[iv_ntr]/`beta_main',.01)
		estadd local dprop = round(_b[iv_ntr]/`beta_main',.01) - round((`arts')/(`tot'),.01)
		
			local propD= round(`arts'/(`tot'),.01)
			local propeffD = round(_b[iv_ntr]/`beta_main',.01)
			
		sum sh_stud_arts02
		estadd local elast = round((_b[iv_ntr]*(1/`r(mean)')*(1/10)),.01)		
		
		
	**QUALITY OF UNIVERSITY	
	
	
		foreach l in ar_p025 ar_p2550 ar_p5075 ar_p75100 tot {
		sum stud_`l' if year==2002 & balanced==1
		local `l' = r(mean)
		}
		
		
		
	//Panel C	
 		eststo Z: reg shc_stud_tot_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode) 
		local beta_main = _b[iv_ntr]
		
 		eststo A: reg shc_stud_ar_p025_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode) 
		estadd local prop= round(`ar_p025'/(`tot'),.01)
		estadd local propeff = round(_b[iv_ntr]/`beta_main',.01)
		estadd local dprop = round(_b[iv_ntr]/`beta_main',.01) - round((`ar_p025')/(`tot'),.01)
		
				local propA= round(`ar_p025'/(`tot'),.01)
				local propeffA = round(_b[iv_ntr]/`beta_main',.01)
		
		sum sh_stud_ar_p02502
		estadd local elast = round((_b[iv_ntr]*(1/`r(mean)')*(1/10)),.01)
		
 		eststo B: reg shc_stud_ar_p2550_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode) 
		estadd local prop= round(`ar_p2550'/(`tot'),.01)
		estadd local propeff = round(_b[iv_ntr]/`beta_main',.01)
		estadd local dprop = round(_b[iv_ntr]/`beta_main',.01) - round((`ar_p2550')/(`tot'),.01)
		
				local propB= round(`ar_p2550'/(`tot'),.01)	
				local propeffB = round(_b[iv_ntr]/`beta_main',.01)
				
		sum sh_stud_ar_p255002
		estadd local elast = round((_b[iv_ntr]*(1/`r(mean)')*(1/10)),.01)
		
 		eststo C: reg shc_stud_ar_p5075_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode) 
		estadd local prop= round(`ar_p5075'/(`tot'),.01)
		estadd local propeff = round(_b[iv_ntr]/`beta_main',.01)
		estadd local dprop = round(_b[iv_ntr]/`beta_main',.01) - round((`ar_p5075')/(`tot'),.01)
		
				local propC= round(`ar_p5075'/(`tot'),.01)
				local propeffC = round(_b[iv_ntr]/`beta_main',.01)
				
		sum sh_stud_ar_p507502
		estadd local elast = round((_b[iv_ntr]*(1/`r(mean)')*(1/10)),.01)		
				
				
 		eststo D: reg shc_stud_ar_p75100_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode) 
		estadd local prop= round(`ar_p75100'/(`tot'),.01)
		estadd local propeff = round(_b[iv_ntr]/`beta_main',.01)
		estadd local dprop = round(_b[iv_ntr]/`beta_main',.01) - round((`ar_p75100')/(`tot'),.01)
		
				local propD= round(`ar_p75100'/(`tot'),.01)
				local propeffD = round(_b[iv_ntr]/`beta_main',.01)
		
		sum sh_stud_ar_p7510002
		estadd local elast = round((_b[iv_ntr]*(1/`r(mean)')*(1/10)),.01)
		
		
			
		**STUDENT FUNDING	
		
		
		
		sum stud_tot if year==2002 & balanced==1
		local tot=r(mean)
		sum stud_nonfunded if year==2002 & balanced==1
		local nonfunded = r(mean)
		sum stud_univ_funded if year==2002 & balanced==1
		local funded = r(mean)
		
		
	//Panel D	
		
		eststo Z: reg shc_stud_tot_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode) 
		local beta_main = _b[iv_ntr]
		
		
 		 eststo A: reg shc_stud_univ_funded_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode) 	
		 estadd scalar prop= round(`funded'/`tot',.01)
		 estadd scalar propeff = round(_b[iv_ntr]/`beta_main',.01)
 		 estadd scalar dprop = round(round(_b[iv_ntr]/`beta_main',.01) - round((`funded')/(`tot'),.01),.01)

				local propA= round(`funded'/(`tot'),.01)
				local propeffA = round(_b[iv_ntr]/`beta_main',.01)
		
		sum sh_stud_univ_funded02
		estadd local elast = round((_b[iv_ntr]*(1/`r(mean)')*(1/10)),.01)
		
		
 		eststo B: reg shc_stud_nonfunded_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode) 	
		estadd scalar prop= round(`nonfunded'/`tot',.01)
		estadd scalar propeff = round(_b[iv_ntr]/`beta_main',.01)
		estadd scalar dprop = round(round(_b[iv_ntr]/`beta_main',.01) - round((`nonfunded')/(`tot'),.01),.01)

				local propB= round(`nonfunded'/`tot',.01)
				local propeffB = round(_b[iv_ntr]/`beta_main',.01)
				
		sum sh_stud_nonfunded02
		estadd local elast = round((_b[iv_ntr]*(1/`r(mean)')*(1/10)),.01)		
		
			
				
		**FUNDING
		
		
		foreach l in fpo_p025 fpo_p2550 fpo_p5075 fpo_p75100 tot {
		sum stud_`l' if year==2002 & balanced==1
		local `l' = r(mean)
		}
		
		//Panel E
		
		eststo Z: reg shc_stud_tot_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode) 
		local beta_main = _b[iv_ntr]
		
		eststo A: reg shc_stud_fpo_p025_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode) 
		estadd scalar prop= round(`fpo_p025'/(`tot'),.01)
		estadd scalar propeff = round(_b[iv_ntr]/`beta_main',.01)
		estadd scalar dprop = round(_b[iv_ntr]/`beta_main',.01) - round((`fpo_p025')/(`tot'),.01)
		
				local propA= round(`fpo_p025'/(`tot'),.01)
				local propeffA = round(_b[iv_ntr]/`beta_main',.01)
		
		sum sh_stud_fpo_p02502
		estadd local elast = round((_b[iv_ntr]*(1/`r(mean)')*(1/10)),.01)		
		
		
		eststo B: reg shc_stud_fpo_p2550_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode) 
		estadd scalar prop= round(`fpo_p2550'/(`tot'),.01)
		estadd scalar propeff = round(_b[iv_ntr]/`beta_main',.01)
		estadd scalar dprop = round(_b[iv_ntr]/`beta_main',.01) - round((`fpo_p2550')/(`tot'),.01)
		
				local propB= round(`fpo_p2550'/(`tot'),.01)	
				local propeffB round(_b[iv_ntr]/`beta_main',.01)
		
		sum sh_stud_fpo_p255002
		estadd local elast = round((_b[iv_ntr]*(1/`r(mean)')*(1/10)),.01)		
				
		eststo C: reg shc_stud_fpo_p5075_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode) 
		estadd scalar prop= round(`fpo_p5075'/(`tot'),.01)
		estadd scalar propeff = round(_b[iv_ntr]/`beta_main',.01)
		estadd scalar dprop = round(_b[iv_ntr]/`beta_main',.01) - round((`fpo_p5075')/(`tot'),.01)
		
				local propC= round(`fpo_p5075'/(`tot'),.01)
				local propeffC = round(_b[iv_ntr]/`beta_main',.01)
			
		sum sh_stud_fpo_p507502
		estadd local elast = round((_b[iv_ntr]*(1/`r(mean)')*(1/10)),.01)		
		
		eststo D: reg shc_stud_fpo_p75100_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode) 
		estadd scalar prop= round(`fpo_p75100'/(`tot'),.01)
		estadd scalar propeff = round(_b[iv_ntr]/`beta_main',.01)
		estadd scalar dprop = round(_b[iv_ntr]/`beta_main',.01) - round((`fpo_p75100')/(`tot'),.01)
		
				local propD= round(`fpo_p75100'/(`tot'),.01)
				local propeffD = round(_b[iv_ntr]/`beta_main',.01)
		
		sum sh_stud_fpo_p7510002
		estadd local elast = round((_b[iv_ntr]*(1/`r(mean)')*(1/10)),.01)		
		
